package com.parsechina.hpush.broker.parser;

import io.netty.handler.codec.mqtt.*;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public class PubRelMessage extends PushMessage {
    private static final long serialVersionUID = 8284780031412617245L;

    private MqttQoS qos;
    private int messageId;

    public PubRelMessage(MqttMessage msg) {
        super(msg);
        MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) getMsg().variableHeader();
        messageId = variableHeader.messageId();
    }

    public PubRelMessage() {
    }

    public int getMessageId() {
        return messageId;
    }

    public void setMessageId(int messageId) {
        this.messageId = messageId;
    }

    public MqttQoS getQos() {
        return qos;
    }

    public void setQos(MqttQoS qos) {
        this.qos = qos;
    }

    public MqttMessage build() {
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, false, qos, false, 0);
        MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
        return new MqttMessage(fixedHeader, variableHeader);
    }
}
